#!/bin/bash

# 确保目标目录存在
mkdir -p pages
mkdir -p utils
mkdir -p images
mkdir -p custom-tab-bar

# 移动pages目录
find miniprogram/pages -type f | while read file; do
  # 获取相对路径
  rel_path=${file#miniprogram/}
  target_dir=$(dirname "$rel_path")
  
  # 创建目标目录
  mkdir -p "$target_dir"
  
  # 如果目标文件已存在，先备份
  if [ -f "$rel_path" ]; then
    mv "$rel_path" "${rel_path}.bak"
  fi
  
  # 复制文件
  cp "$file" "$rel_path"
  echo "Copied: $file -> $rel_path"
done

# 移动utils目录
if [ -d "miniprogram/utils" ]; then
  find miniprogram/utils -type f | while read file; do
    rel_path=${file#miniprogram/}
    target_dir=$(dirname "$rel_path")
    mkdir -p "$target_dir"
    if [ -f "$rel_path" ]; then
      mv "$rel_path" "${rel_path}.bak"
    fi
    cp "$file" "$rel_path"
    echo "Copied: $file -> $rel_path"
  done
fi

# 移动images目录
if [ -d "miniprogram/images" ]; then
  find miniprogram/images -type f | while read file; do
    rel_path=${file#miniprogram/}
    target_dir=$(dirname "$rel_path")
    mkdir -p "$target_dir"
    if [ -f "$rel_path" ]; then
      mv "$rel_path" "${rel_path}.bak"
    fi
    cp "$file" "$rel_path"
    echo "Copied: $file -> $rel_path"
  done
fi

# 移动custom-tab-bar目录
if [ -d "miniprogram/custom-tab-bar" ]; then
  find miniprogram/custom-tab-bar -type f | while read file; do
    rel_path=${file#miniprogram/}
    target_dir=$(dirname "$rel_path")
    mkdir -p "$target_dir"
    if [ -f "$rel_path" ]; then
      mv "$rel_path" "${rel_path}.bak"
    fi
    cp "$file" "$rel_path"
    echo "Copied: $file -> $rel_path"
  done
fi

echo "迁移完成！"
echo "请检查文件是否正确移动，然后可以手动删除miniprogram和src目录。" 